﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.Kinect.Nui;

namespace KinectGestureRecognizer.Helper
{
    public class JointCollector
    {
        int maxNumberOfJointsToCollect;
        int actualJointIndex;
        Joint[] joints;

        public Joint getFirstJoint { get { return joints[actualJointIndex]; } }
        public Joint getLastJoint { get { if (actualJointIndex == 0) return joints[maxNumberOfJointsToCollect - 1]; else return joints[actualJointIndex - 1]; } }

        public JointCollector(int maxNumberOfJointsToCollect)
        {
            this.maxNumberOfJointsToCollect = maxNumberOfJointsToCollect;
            this.joints = new Joint[maxNumberOfJointsToCollect];
            this.actualJointIndex = 0;
        }

        public void addJointToCollector(Joint joint)
        {
            joints[actualJointIndex] = joint;
            actualJointIndex = ++actualJointIndex % maxNumberOfJointsToCollect;
        }

        public Joint[] getJointsCollection()
        {
            Joint[] jointsToReturn = new Joint[maxNumberOfJointsToCollect];
            int tempIndex = actualJointIndex;

            for (int i = 0; i < maxNumberOfJointsToCollect; i++)
            {
                jointsToReturn[i] = this.joints[tempIndex % maxNumberOfJointsToCollect];
                tempIndex++;
            }

            return jointsToReturn;
        }

        public void empyCollector()
        {
            this.joints = new Joint[maxNumberOfJointsToCollect];
        }
    }
}
